﻿var connection = $.connection(sUrl);
var template = $.templates("#eventListTemplate");

$("#wi").click(function () {
    $.ajax({
        url: '/home/TestWI',
        data: null,
        cache: false
    });
});

$(function () {
    connection.received(function (data) {
        var count = $('#eventsList a').length;
        if (count > 3) {
            $('#eventsList a:last-child').remove();
        }
        var content = template.render(data);
        $('#eventsList').prepend(content).fadeIn(600);
        
    });
    connection.error(function (data) {
        $('#messages').html(data);
    });
    connection.stateChanged(connectionStateChanged);
    connection.start({ waitForPageLoad: false });
});
function connectionStateChanged(state) {
    var stateConversion = { 0: 'connecting', 1: 'connected', 2: 'reconnecting', 4: 'disconnected' };
    console.log('SignalR state changed from: ' + stateConversion[state.oldState]
     + ' to: ' + stateConversion[state.newState]);
}